#include <stdio.h> 
#include <stdlib.h>
const char *Names[]={ 
    "Populus","Tristitia","Albus","Fortuna Major", 
    "Rubeus","Acquisitio","Conjunctio","Caput Draconis", 
    "Laetitia","Carcer","Tristitia","Puella", 
    "Fortuna Minor","Puer","Cauda Draconis","Via" 
    }; 
const char *Positions[]={ 
    "1st Mother","2nd Mother","3rd Mother","4th Mother", 
    "1st Daughter","2nd Daughter","3rd Daughter","4th Daughter", 
    "1st Niece","2nd Niece","3rd Niece","4th Niece", 
    "Right Witness","Left Witness","JUDGE","Reconciler"}; 
void set_mothers(int *); 
void output(const int *); 
void divination(int *); 
int main(int argc, char* argv[]) 
{ 
    int geochart[16]={0}; 
    set_mothers(geochart); 
    divination(geochart); 
    output(geochart);         
    return 0;  } 
void output(const int *chart) 
{ 
    int i; 
    for(i=0;i<16;i++) printf("%x%s",chart[i],!((i+1)%4)?"\n":" "); 
    for(i=0;i<16;i++) 
        printf("%d. The %s: %s\n",i+1,Positions[i],Names[chart[i]]);  } 
void divination(int *chart) 
{ 
    int i,j,k,mod[4]; 
    /* The Daughters */ 
    for(i=4,j=8;i<8;i++,j/=2) { 
        for(k=0;k<4;k++) mod[k]=chart[k]%(j*2); 
        chart[i]=mod[0]/j*8+mod[1]/j*4+mod[2]/j*2+mod[3]/j; 
    } 
    /* The Others */ 
    for(i=8,j=0;i<15;i++,j+=2) chart[i]=chart[j]^chart[j+1]; 
    /* The Reconciler */ 
    chart[15]=chart[0]^chart[14];  } 
void set_mothers(int *chart) { 
    char line[5]; 
    int i; 
    printf("Enter The Mothers: "); // in hex
    scanf("%s",line); 
    for(i=0;line[i]!=0;i++); 
    if(i!=4) { printf("Incorrect!"); exit(1); }; 
    for(i=0;i<4;i++) { 
        if(line[i]<='9' && line[i]>='0') chart[i]=line[i]-'0'; 
        else switch(line[i]) { 
            case 'a': case 'A': chart[i]=10; break; 
            case 'b': case 'B': chart[i]=11; break; 
            case 'c': case 'C': chart[i]=12; break; 
            case 'd': case 'D': chart[i]=13; break; 
            case 'e': case 'E': chart[i]=14; break; 
            case 'f': case 'F': chart[i]=15; break; 
            default: printf("Incorrect!"); exit(1); 
        } 
    }  
} 
 
